<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>axios基本使用</title>
</head>

<body>
    <button id="laugh">
        笑话
    </button>
    <button id="register">
        注册
    </button>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script>
        document.querySelector('#laugh').addEventListener('click', function() {
            axios.get('https://autumnfish.cn/api/joke/list?num=4').then(function(response) {
                console.log(response);
                console.log(response.data.jokes);
            }, function() {
                console.log('错误了');
            })
        });
        document.querySelector('#register').addEventListener('click', function() {
            axios.post('https://autumnfish.cn/api/user/reg', {
                username: '连浩伟'
            }).then(function(response) {
                console.log(response);
                console.log(response.data);
            })
        })
    </script>
</body>

</html>